﻿//Register the event
Sys.Application.add_load(page_Load);
Sys.Application.add_unload(page_unLoad);
function page_Load(sender, e)
{
  $addHandler($get("Departments"), "change", GetData_OnClick);
}
function page_unLoad(sender, e)
{
  $removeHandler($get("Departments"), "change", GetData_OnClick);
}

function GetData_OnClick(sender, e)
{
  document.getElementById("employeeCount").innerHTML="";
  $get("loading").style.display = "block";
  DemoWeb2008.UIWebService.HRService.GetEmployeeName(document.getElementById("Departments").value, OnSuccess, OnFail);
  
}
function OnSuccess(result)
{
  $get("loading").style.display = "none";
  var data = "";
  for(var i = 0;i<result.tables.length;i++)
  {
    for(var j = 0;j<result.tables[i].rows.length;j++)
    {
        //alert(result.tables[i].rows[j].name);
        data += "<tr><td>"+result.tables[i].rows[j].name+"</td></tr>";
    }
  }
  document.getElementById("employeeCount").innerHTML = "<table border=1>"+"<th>Name</th>"+ data + "</table>";
}

function OnFail()
{
 alert("Server no response");
}